﻿CREATE PROCEDURE [maint].[DbMaintenance]
@DbName [sysname], @OutputDiagnostics BIT=0
AS
BEGIN
	DECLARE @RC int
	SET @RC = 0

	IF(@OutputDiagnostics = 1)
		PRINT OBJECT_NAME(@@PROCID)

	EXEC @RC = [maint].[CheckDB] @DbName = @DbName, @OutputDiagnostics = @OutputDiagnostics;	
	
	IF (@RC = 0)
		EXEC @RC = [maint].[UpdateStats]	@DbName = @DbName, @OutputDiagnostics = @OutputDiagnostics;	
	
	IF (@RC = 0)
		EXEC @RC = [maint].[BackupToDevice] @DbName = @DbName, @OutputDiagnostics = @OutputDiagnostics;
		
	IF (@RC = 0)
		EXEC @RC = [maint].[DefragDb] @DbName = @DbName, @OutputDiagnostics = @OutputDiagnostics;

	RETURN(@RC)
END